#include "typedef.h"
#include "config_ap.h"
#include "ui.h"
#include "my_ui.h"
#include "disp.h"
#include "uart.h"
#include "lcd.h"
#include "key.h"
#include "front.h"
#include "msgfor_hot.h"

extern SYSINFO _xdata sysinfo;

u8 volume_adjust(u8 mode)
{	
	if(mode == UI_SLIDER_INC)
	{
		sysinfo.volume ++;	
		if(sysinfo.volume >7) sysinfo.volume = 7;			
	}

	else if(mode == UI_SLIDER_DEC)
	{
		sysinfo.volume --;
		if(sysinfo.volume == 0xff ) sysinfo.volume = 0;
	}
			
	if(sysinfo.volume>7) 
		sysinfo.volume = 7;				

	disp_main_vol(sysinfo.volume);
		
	return sysinfo.volume*14;
}

u8 volume_Slider()
{
	uint8 xdata Msg; 
	uint8 xdata currentpos;
	uint8 xdata autoruntime=SLIDER_NOMOVE_TIMEEXIT;
//	u16 xdata m;
	clear_lcd(); 
	currentpos = volume_adjust(UI_SLIDER_CURR_VALUE);
	draw_slider(currentpos,5,SLIDERLENGTH);
	draw_lcd(0, LCDPAGE);
	while(1)
	{
		Msg = app_get_msg();
		switch(Msg)
		{
			case MSG_KEY_PP:
				return 0;
			
			case MSG_KEY_FR: //HOLD
			case MSG_KEY_PREV:
				autoruntime=SLIDER_NOMOVE_TIMEEXIT;	
				clear_lcd_area(1,4);		
				currentpos = volume_adjust(UI_SLIDER_DEC);
				draw_slider(currentpos,5,SLIDERLENGTH);
				draw_lcd(0,8);
				break;
	
			case MSG_KEY_FF:	//HOLD
			case MSG_KEY_NEXT:
				autoruntime=SLIDER_NOMOVE_TIMEEXIT;
				currentpos = volume_adjust(UI_SLIDER_INC);
				draw_slider(currentpos,5,SLIDERLENGTH);
				draw_lcd(0,8);
				break;

            case MSG_100MS:
            case MSG_200MS: 
                 break;

			case MSG_HALF_SECOND:
				autoruntime-- ;
				if(autoruntime == 0 )
				{
					return 0 ;
				}	
				break;

			case MSG_MUSIC_SELECT_NEW_DEVICE:
			case MSG_MUSIC_NEW_DEVICE_IN:					
			case MSG_CHANGE_WORK_MODE:
				put_msg_lifo(Msg);
				return EXIT_MENU;

			default:
                if(Msg == NO_MSG)
                    break;
				ap_handle_hotkey(Msg);
				break;
		}
	}
}
